﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace PictureBoard4.Shape
{
    /// <summary>
    ///  图片
    /// </summary>

   public class CarveImage:Shape
    {
        public Point StartPoint { get; set; }//开始坐标
        public Point EndPoint { get; set; }//结束坐标
        public Image CImage { get; set; }//图片
      
       
        #region 重写父类的方法
        public override void Add(System.Drawing.Point p)
        {
            if (StartPoint == EndPoint)
                StartPoint = p;
            else
                EndPoint = p;
        }
       //保存图片
        public void SetImage(Image img)
        {
            Image bitmap = new Bitmap(Math.Abs(StartPoint.X - EndPoint.X), Math.Abs(StartPoint.Y - EndPoint.Y));
            Graphics g = Graphics.FromImage(bitmap);
            g.DrawImage(img, new Rectangle(0, 0, bitmap.Width, bitmap.Height), new Rectangle(StartPoint.X, StartPoint.Y, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
            CImage = bitmap;
            g.Dispose();
        }
        public override bool Draw(System.Drawing.Graphics g)
        {
            if (CImage != null)
            g.DrawImage(CImage, StartPoint);
            return true;
        }
        public override bool GetBound(ref System.Drawing.Point StartPoint, ref System.Drawing.Point EndPoint)
        {
            StartPoint = this.StartPoint;
            EndPoint = this.EndPoint;
            return true;
        }
        public override void Move(System.Drawing.Point Point)
        {
            if (Point.X != 0)
            {
                Point TempStartPoint = StartPoint;
                Point TempEndPoint = EndPoint;

                StartPoint = new Point(TempStartPoint.X + Point.X, TempStartPoint.Y + Point.Y);
                EndPoint = new Point(TempEndPoint.X + Point.X, TempEndPoint.Y + Point.Y);
            }
        }
        #endregion
    }
}
